public static void Factorial(int n)
{
var number = new int[999999];
number[0] = 1;
int numLength = 1;
for (int times = 2; times <= n; times++)
numLength = Multiply(times, number,numLength);
for (int i = numLength - 1; i >= 0; i--)
Console.Write(number[i]);
}
static int Multiply(int times, int[] number,int numLength)
{
int carry = 0;
for (int i = 0; i < numLength; i++)
{
int product = number[i] * times + carry;
number[i] = product % 10;
carry = product / 10;
}
while (carry != 0)
{
number[numLength] = carry % 10;
carry /= 10;
numLength++;
}
return numLength;
}
<?php
$num = 3;
$factorial = 1;
if($num != 0) {
for($i = $num; $i>=1; $i--) {
$factorial = $factorial * $i;
}
}
else {
$factorial = 1;
}
echo "Factorial of $num is $factorial";
?>